import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';

enum Api {
  list = '/dps/processingData/list',
  queryProductError = '/dps/processingData/queryProductErrorByErrId',
  queryOrgError = '/dps/processingData/queryOrgErrorByErrId',
  reprocess = '/dps/processingData/reprocess',
  processBatch = '/dps/processingData/processBatch',
  delete = '/dps/processingData/delete',
  exportXls = '/dps/processingData/exportXls',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({ url: Api.list, params });

/**
 * 查询报错详情
 * @param params
 */
export const queryErrorInfo = (params) => defHttp.get({ url: Api[params.apiName] + '/' + params.errId });

/**
 * 批量处理
 * @param ids
 * @param handleSuccess
 */
export const batchProcess = ({ ids }, handleSuccess) => {
  Modal.confirm({
    title: '确认批量?',
    content: '是否重新处理选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: async () => {
      await defHttp.get({ url: Api.processBatch, params: { ids } });
      handleSuccess();
    },
  });
};

export const reprocess = (params, handleSuccess) => {
  Modal.confirm({
    title: '重新处理?',
    content: '是否重新处理选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: async () => {
      await defHttp.get({ url: Api.reprocess + '/' + params.dataId });
      handleSuccess();
    },
  });
};

export const deleteData = (params, handleSuccess) => {
  Modal.confirm({
    title: '作废?',
    content: '确认作废当前选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: async () => {
      await defHttp.get({ url: Api.delete + '/' + params.dataId });
      handleSuccess();
    },
  });
};


export const saveOrUpdate = (params) => defHttp.get({ url: Api.list, params });
